﻿using System;
using System.Drawing;
using System.Windows.Forms;

using Model.Data;

using Utilities;

namespace WssClient
{
    public partial class frmClient : Form
    {
        public frmClient()
        {
            InitializeComponent();
            this.FormClosing += FrmClient_FormClosing;
            Text = $"{GVar.item.title} - 报表打印客户端(Ver:{GVar.ver})";
            MainNotifyIcon.Text = MainNotifyIcon.BalloonTipText = MainNotifyIcon.BalloonTipTitle = Text;
        }

        private void FrmClient_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void MainNotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if(GVar.ShowYNCMessage("确定退出吗?") == DialogResult.Yes)
            {
                Application.ExitThread();
            }
        }

        private void frmClient_Load(object sender, EventArgs e)
        {
            int index = 1;
            do
            {
                this.comboBox1.Items.Add(index);
            } while(index++ < 10);

            try
            {
                this.comboBox1.SelectedIndex = GVar.printIndex - 1;
                if(GVar.printMode)
                {
                    this.radioButton1.Checked = true;
                }
                else
                {
                    this.radioButton2.Checked = true;
                }
            }
            catch(Exception)
            {
            }
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var value = this.comboBox1.SelectedItem;
            if(value != null)
            {
                GVar.UpdatePrintIndex(CommonHelper.FormatInt(value));
            }
        }

        private void 打印_CheckedChanged(object sender, EventArgs e)
        {
            GVar.UpdatePrintMode(true);
        }

        private void 预览_CheckedChanged(object sender, EventArgs e)
        {
            GVar.UpdatePrintMode(false);

        }
    }
}
